<html>
<head><meta charset="utf-8"><title>what Rust values are best supported by the unwind choice · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/what.20Rust.20values.20are.20best.20supported.20by.20the.20unwind.20choice.html">what Rust values are best supported by the unwind choice</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="191043558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/what%20Rust%20values%20are%20best%20supported%20by%20the%20unwind%20choice/near/191043558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/what.20Rust.20values.20are.20best.20supported.20by.20the.20unwind.20choice.html#191043558">(Mar 18 2020 at 21:18)</a>:</h4>
<p>Here is my "current stance" -- subject to change as ever. Something we didn't quite get into when considering the various options is "what the choice says about Rust" -- or maybe, what kind of coding we would ultimately recommend. It seems to me that a strong Rust value is that:</p>
<ul>
<li>idiomatic Rust code is portable by default, both across platforms but also across panic=unwind and panic=abort;</li>
<li>but we offer the ability to maximally take advantage of your platform as well.</li>
</ul>
<p>To that end, no matter what proposal we wound up with, it seems like we would recommend that code authors:</p>
<ul>
<li>catch your C++-based exceptions in C++ land and convert them to error codes, so that you are portable across panic=abort and panic=unwind;</li>
<li>only use longjmp or pthread-exit when there are no destructors, so that you are portable across platforms as well as panic=abort/unwind.</li>
</ul>
<p>I think that this implies to me that it might be beneficial to separate "C" and "C unwind". It means that you have to be a bit explicit when you're relying on something non-portable, but that's perhaps a good thing, and it lets us lint more effectively. It also means we can put shims that detect <em>all</em> non-forced-unwinding across a C boundary and abort, thus helping to detect portability hazards. We might want to limit those to debug-mode because they would make binaries somewhat bigger, though we also ought to measure that more carefully (it wasn't too hard to implement when I tried).</p>
<p>I think I'll try to do a longer write-up, and also experiment a bit with what I see as the strongest argument the other way, but I was curious to write this one out. =)</p>
<p>(I feel that the strongest argument the other way is one that speaks to Rust enabling smooth interop with native code, and the overall simplicity of the ABI story -- extern "C" means the native ABI, full stop. But this argument of course is limited by the fact that we still enable interop in both proposals, albeit with a small speedbump of using the "C unwind" ABI, and my feeling that people will ultimately be able to understand that propagating exceptions across Rust code requires you to "opt in".)</p>
<p><strong>Side note that this exercise is making me really want to take a stab at writing out the values that Rust strives for.</strong></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>